import numpy as np 

def train_test_split(X, y, test_ratio=0.2, seed=None):
	assert X.shape[0] == y.shape[0], \
	"the size of X must be equal to the size of y"
	assert 0.0 <= test_ratio <= 1.0, \
	"test_tatio must be valid"

	if seed:
		np.random.seed(seed)

	shuffled_indexes = np.random.permutation(len(X))   	#150个索引的随机排列
	
	test_size = int(len(X)*test_ratio)					#测试数据集格式
	test_indexes = shuffled_indexes[:test_size]      	#前20%为测试数据集
	train_indexes = shuffled_indexes[test_size:]     	#后80%为训练数据集

	X_train = X[train_indexes]							#120*4
	y_train = y[train_indexes]							#120

	X_test = X[test_indexes]							#30*4
	y_test = y[test_indexes]							#30

	return X_train, X_test, y_train, y_test